package com.itheim.health.jobs;

import com.itheima.health.common.RedisConst;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import redis.clients.jedis.JedisPool;

import java.util.Iterator;
import java.util.Set;

/**
 * @autahor: csl
 * @date: 2019/7/19
 * @description:
 * @version:1.0
 */
@Service
public class ClearImagesJobs {
    @Autowired
    private JedisPool jedisPool;
    public void clearImageJob(){
         try {
             //System.out.println("clearImageJob....jedisPool:"+jedisPool!=null+"getResource:"+jedisPool.getResource());
             //获取两个数据差集
             Set<String> set = jedisPool.getResource().sdiff(RedisConst.SETMEAL_PIC_RESOURCES, RedisConst.SETMEAL_PIC_DB_RESOURCES);
             if (set==null){
                 System.out.println("clearImageJob......set is null");
                 return;
             }
             Iterator<String> iterator = set.iterator();
             while (iterator.hasNext()){
                 String picName = iterator.next();
                 QiniuUtils.deleteFileFromQiniu(picName);
                 jedisPool.getResource().srem(RedisConst.SETMEAL_PIC_RESOURCES,picName);
                 System.out.println("clearImageJob......del:"+picName);
             }
         }catch (Exception e){
                     e.printStackTrace();
                 }
    }

}
